package r6.pierwszy.raz;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.util.Date;

import javax.swing.JOptionPane;
import javax.swing.Timer;

public class Czasomierz implements Runnable {

	private class TimerListener implements ActionListener {
		
		@SuppressWarnings("unused")
		private Czasomierz outer;

		private TimerListener(Czasomierz czasomierz){
			outer = czasomierz;
		}

		@Override
		public void actionPerformed(ActionEvent e) {
			if(beep)
				System.out.println("Beep!");
			System.out.println(DateFormat.getTimeInstance().format(new Date()));
		}

	}

	private int interval;
	private boolean beep;

	public Czasomierz(int interval, boolean beep) {
		this.interval = interval;
		this.beep = beep;
	}

	public Czasomierz() {
		this(1000);
	}

	public Czasomierz(int i) {
		this(i, false);
	}

	@Override
	public void run() {
		new Timer(interval, new TimerListener(this)).start();
		JOptionPane.showMessageDialog(null, "Koniec");
		System.exit(0);
	}

}
